package cn.usain.controller;

import cn.usain.service.RatingStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 20171
 */
@RestController
@RequestMapping("orders")
public class RatingStatisticsController {

    @Autowired
    private RatingStatisticsService ratingStatisticsService;

    @PostMapping("/get-rating-statistics")
    public Map<String, Object> getRatingStatistics(@RequestBody Map<String, Object> queryParams) {
        Map<String, Object> result = new HashMap<>();
        List<Double> ratings = new ArrayList<>();
        List<Integer> counts = new ArrayList<>();

        List<Map<String, Object>> statisticsData = ratingStatisticsService.getRatingStatistics(queryParams);
        for (Map<String, Object> data : statisticsData) {
            ratings.add((Double) data.get("driverRating"));
            counts.add((Integer) data.get("count"));
        }

        result.put("ratings", ratings);
        result.put("counts", counts);
        return result;
    }

    @GetMapping("driver-ratings")
    public List<Map<String, Object>> getDriverRatings() {
        return ratingStatisticsService.countDriverRatings();
    }
}